﻿#!/usr/bin/env python
#coding:utf-8

from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpRequest
from django.template import RequestContext
from datetime import datetime

from models import AppSettings

from django.contrib.auth.decorators import login_required

#company = AppSettings.objects.get(name='company_name').value
#system_name = AppSettings.objects.get(name='system_name').value
company = ''
system_name = ''

def home(request):
    """Renders the home page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/index.html',
        context_instance = RequestContext(request,
        {
            'title':'首页',
            'company':company,
            'system_name':system_name,
            'year':datetime.now().year,
        })
    )

def settings(request):
    """Renders the contact page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/settings.html',
        context_instance = RequestContext(request,
        {
            'title':'',
            'message':'Your contact page.',
            'year':datetime.now().year,
        })
    )

def about(request):
    """Renders the about page."""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/about.html',
        context_instance = RequestContext(request,
        {
            'title':'',
            'message':'业余时间为方便公司同事写日志而做的日志项目，本项目开源，有兴趣的同事可以提交修改分支，测试通过后我会并入主分支。',
            'year':datetime.now().year,
        })
    )

@login_required()
def diary(request):
    """工作日志"""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/diary.html',
        context_instance= RequestContext(request,
         {
             'title':'工作日志',
             'day': datetime.now().date(),
             'year':datetime.now().year,
             'company':company,
             'd_diary_list':[],
             'm_diary_list':[],
         })
    )



@login_required()
def weekly(request):
    """周报"""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/weekly.html',
        context_instance= RequestContext(request,
         {
             'title':'项目周报',
             'day': datetime.now().date(),
             'year':datetime.now().year,
             'company':company,
             'object_list':[],
         })
    )

@login_required()
def locale_diary(request):
    """现场工作日志"""
    assert isinstance(request, HttpRequest)
    return render(
        request,
        'app/locale_diary.html',
        context_instance= RequestContext(request,
         {
             'title':'现场工作日志',
             'day': datetime.now().date(),
             'year':datetime.now().year,
             'company':company,
             'object_list':[],
         })
    )


def edit_d_diary(request, id):
    """提交编辑开发日志的结果"""
    pass

def remove_d_diary(request, id):
    """提交删除开发日志的结果"""
    pass

def edit_m_diary(request, id):
    """提交编辑维护日志结果"""
    pass

def remove_m_diary(request, id):
    """提交删除维护日志结果"""
    pass

